home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / qlib205.zip / QLIB.ZIP / C / IASM.C < prev    next >
C/C++ Source or Header  |  1997-07-09  |  3KB  |  103 lines

  1. //#define DEBUG
  2.  
  3. // Inline ASM Convert v1.01  32bit
  4. //  By:Peter Quiring  (source copied from PASM)
  5.  
  6. // Please note : iASM was originally thought up by Cameron Bushartd
  7.  
  8. /*/
  9. For WATCOM C/C++
  10.  
  11. Notes:
  12.   -after creating this I've found some minor bugs in PASM since I copied the
  13.    source from PASM for this little util.
  14.   -DO NOT use local variables inside ASM blocks since they may be in
  15.    registers or something.  Just preserve everything and use only
  16.    global data. (if you need to use local stuff or parameters pushed to
  17.    a func you'll need to use the proper Watcom ASM {} style which
  18.    sucks and is a pAin in the ass)
  19. Advantages:
  20.   -allow "asm {}" blocks in Watcom C files
  21.   -allow single asm statements,  eg:  asm mov ax,3
  22.   -you can keep labels inside the {} (watcom only and BCv5.0)
  23.   -ALL output always goes to c.tmp (unlike PASM which goes to asm.tmp & _str_.tmp)
  24. Disadvantages:
  25.   -iASM looks for 'ASM ' at the begining of ANY line! So if a comment starts
  26.   with asm in a line it will cause errors.  It's too much to seek out commment
  27.   blocks and such (considering they could be in strings and it's just too much)
  28.   but this should hardly even happen.  
  29. /*/
  30.  
  31. #include <qlib.h>
  32. #include <string.h>
  33. #include <dos.h>
  34. #include <stdlib.h>
  35. #include <stdio.h>
  36.  
  37. #define mh 64   //max handles  (the incs)
  38. #define bufsiz 32*1024  //buffer size
  39. byte buf[256];  //current line
  40. byte str[256];
  41. byte *bufo1;
  42. word bufp1;
  43. byte * bufin[mh];
  44. word bufip[mh];  //buffer pos
  45. word bufis[mh];  //buffer size left  (bufsiz-pos)
  46. word bufln[mh];  //current line #
  47. byte buffn[mh][80];  //file names
  48. word cnum;  //current asm block number
  49. int ho1;  // handle out for large C file  (c.tmp)
  50. byte ho1on;  //handle above has been created
  51. int h;       // current file handle (in)
  52. int hs[mh];  // handles  (all kept in place)  (requires a lot of handles in config.sys)
  53. byte ch;     // current handle # (within hs and all other things)
  54. byte EOFF[mh];     // flag (indicates that we have hit EOF)
  55. byte *file;  //pts to filename to open
  56. byte enter[3]={13,10,0};
  57. byte *inc;  //INCLUDE name from enviroment
  58. word incsiz;  //size of inc string
  59. byte t2[80];
  60. byte first;
  61. byte obuf[80];
  62.  
  63. //Protos
  64. void flush(void);
  65. void errorf(byte *s);
  66. void error(byte *s);
  67. void readln(void);
  68. void prefile(void);
  69. void out(byte*);
  70. void asm_pre(void);
  71. void asm_done(void);
  72. void out_asm(byte *s);
  73. void prefile(void);
  74. void out(byte *str);
  75. void setup(void);
  76. void dofile(void);
  77.  
  78. //#define DEBUG
  79. #define IASM
  80. #include "err-i.h"       //these are shared between iASM and PASM
  81. #include "readln.h"
  82. #include "iasm.h"
  83. #include "do.h"
  84.  
  85. void main(void) {
  86.   byte a;
  87.   printf("Watcom C \"inline ASM converter\" v1.01 32bit (by : Peter Quiring)\n");
  88.   ho1on=0;
  89.   bufp1=0;
  90.   bufo1=(void*)malloc(bufsiz);
  91.   if ( (dword)bufo1==ERROR) error("Out of RAM");
  92.   for(a=0;a<mh;a++) bufin[a]=0;
  93.   if (_argc!=2) error("Usage: iASM 'file.c'");
  94.   file=_argv[1];
  95.   ch=255;
  96.   cnum=0;
  97.   setup();
  98.   dofile();
  99.   flush();
  100.   printf("Complete!\n\n");
  101.   exit(0);
  102. }
  103.